package com.ruoyi.wxhouse.service.imp;

import com.ruoyi.house.domain.YjzHouse;
import com.ruoyi.house.domain.YjzHouseImage;
import com.ruoyi.house.mapper.YjzHouseImageMapper;
import com.ruoyi.house.mapper.YjzHouseMapper;
import com.ruoyi.wxhouse.domain.WxHouse;
import com.ruoyi.wxhouse.service.WxHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.stream.Collectors;
@Service
public class WxHouseServiceImpl implements WxHouseService {
    @Autowired
    private YjzHouseMapper yjzHouseMapper;

    @Autowired
    private YjzHouseImageMapper yjzHouseImageMapper;
    /**
     * 查询房源列表
     *
     * @param yjzhouse 房源
     * @return 房源
     */
    @Override
    public List<WxHouse> selectWxHouseList(YjzHouse yjzhouse){
        List<YjzHouse> yjzHouseList = yjzHouseMapper.selectYjzHouseList(yjzhouse);
        return yjzHouseList.stream().map(house -> {
            WxHouse dto = new WxHouse();
            // 映射字段 1.房源id
            dto.setId(house.getId());
            // 映射字段 2.房源标题
            dto.setTitle(house.getTitle());
            // 映射字段 3.房源类型
            dto.setType(house.getType());
            // 映射字段 4.房源面积
            dto.setArea(house.getArea());
            // 5.获取房源照片集合
            List<YjzHouseImage> houseImageList = yjzHouseImageMapper.selectHouseImage(house.getId());
            // 设置完整的图片集合
            dto.setHouseImages(houseImageList);
            // 映射字段 6.房源装修
            dto.setDecorate(house.getDecorate());
            // 映射字段 5.房源楼层
            dto.setFloor(house.getFloor());
            // 映射字段 6.房源区域
            dto.setDistrict(house.getDistrict());
            // 映射字段 7.房源朝向
            dto.setToward(house.getToward());
            // 映射字段 8.房源价格
            dto.setPrice(house.getPrice());
            return dto;
        }).collect(Collectors.toList());
    }

    /**
     *  查询房源图片
     * @param houseId 房源id
     * @return 房源图片
     * */
//    @Override
//    public List<YjzHouseImage> selectHouseImage(Long houseId){
//        return yjzHouseImageMapper.selectHouseImage(houseId);
//    }
}
